//
//  MyViewController.m
//  Beauty
//
//  Created by Snow on 16/8/26.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "MyViewController.h"
#import "MyTableViewCell.h"
#import "GXMacro.h"
#import "GXNetWorkingParser.h"
#import "OptionViewController.h"
#import "UIView+Frame.h"
#import "MyTableViewOfMoment.h"
#import "MyWindowTableViewCell.h"
#import "MineModel.h"
#import "ModelOfMineWindow.h"
#import "ViewControllerOfHotWindow.h"
#import "MyFansViewController.h"
#import "IContractOnViewController.h"
#import "HotWindowViewController.h"
#import "LookMoreViewController.h"
#import "HeadsPicture.h"
#import "LoginViewController.h"
#import "ModelOfLookMoreWindow.h"
#import "ContractStoreViewController.h"
#import "MyWishesViewController.h"
#import "MyPreListViewController.h"
#import "GiftViewController.h"
#import "MyMoneyViewController.h"
@interface MyViewController ()<UITableViewDelegate, UITableViewDataSource, MomentDelegate, MyWindowDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSDictionary *dictionary;
@property (nonatomic, strong) NSMutableArray *arrayOfMoment;
@property (nonatomic, strong) NSMutableArray *arrayOfWindow;
@property (nonatomic, strong) UIImageView *image;
@end

@implementation MyViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
    //获取UserDefault
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    NSString *name = [userDefault objectForKey:@"name"];
    
    if (name == nil)
    {
        LoginViewController *login = [[LoginViewController alloc] init];
        NSLog(@"%@",name);
        [self presentViewController:login animated:YES completion:^{
            self.tabBarController.selectedIndex = 0;
        }];
    }
    [self handleData];
    [self createView];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    
}
- (void)createView
{
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    //右标-设置
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"option"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(option:)];
    //  左标-添加好友
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"addFriends"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(addFriends:)];
    //tableview
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -64, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStyleGrouped];
    _tableView.backgroundColor = [UIColor colorWithWhite:0.902 alpha:1.000];
    _tableView.bounces = NO;
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:@"MyTableViewCell"];
    [_tableView registerClass:[MyTableViewOfMoment class] forCellReuseIdentifier:@"MyTableViewOfMoment"];
    [_tableView registerClass:[MyWindowTableViewCell class] forCellReuseIdentifier:@"MyWindowTableViewCell"];
    [self createFresh];
}
- (void)createFresh
{
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
    }];
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(handleLoadNewData)];
}

- (void)handleData
{
    //获取UserDefault
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    //    NSString *name = [userDefault objectForKey:@"name"];
    NSString *password = [userDefault objectForKey:@"password"];
    _arrayOfMoment = [NSMutableArray array];
    _arrayOfWindow = [NSMutableArray array];
    NSString *url = [NSString stringWithFormat:@"http://www.wantease.com/mobile1/index.php?act=member_index&op=index_1_5&key=%@", password];
    [GXNetWorkingParser GETWithURL:url par:nil success:^(id responseObject) {
        _dictionary = [NSDictionary dictionaryWithDictionary:responseObject[@"datas"][@"member_info"]];
        NSArray *arrOfMoment = responseObject[@"datas"][@"micro_personal"];
        NSArray *arrOfWindow = responseObject[@"datas"][@"micro_personal_class_list"];
        for (NSDictionary *dic in arrOfMoment) {
            MineModel *model = [[MineModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [_arrayOfMoment addObject:model];
        }
        for (NSDictionary *dict in arrOfWindow) {
            ModelOfMineWindow *model = [[ModelOfMineWindow alloc]init];
            [model setValuesForKeysWithDictionary:dict];
            [_arrayOfWindow addObject:model];
        }
        [self tableViewHeaderView];
        [_tableView reloadData];
    } filed:^(NSError *error) {
        
    }];
}
- (void)handleLoadNewData
{
    //获取UserDefault
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
//    NSString *name = [userDefault objectForKey:@"name"];
    NSString *password = [userDefault objectForKey:@"password"];
    _arrayOfMoment = [NSMutableArray array];
    _arrayOfWindow = [NSMutableArray array];
    NSString *url = [NSString stringWithFormat:@"http://www.wantease.com/mobile1/index.php?act=member_index&op=index_1_5&key=%@", password];
[GXNetWorkingParser GETWithURL:url par:nil success:^(id responseObject) {
    _dictionary = [NSDictionary dictionaryWithDictionary:responseObject[@"datas"][@"member_info"]];
    NSArray *arrOfMoment = responseObject[@"datas"][@"micro_personal"];
    NSArray *arrOfWindow = responseObject[@"datas"][@"micro_personal_class_list"];
    for (NSDictionary *dic in arrOfMoment) {
        MineModel *model = [[MineModel alloc]init];
        [model setValuesForKeysWithDictionary:dic];
        [_arrayOfMoment addObject:model];
    }
    for (NSDictionary *dict in arrOfWindow) {
        ModelOfMineWindow *model = [[ModelOfMineWindow alloc]init];
        [model setValuesForKeysWithDictionary:dict];
        [_arrayOfWindow addObject:model];
    } 
    [self tableViewHeaderView];
    [_tableView reloadData];
} filed:^(NSError *error) {
    
}];
    [self.tableView.mj_header endRefreshing];
}
- (void)tableViewHeaderView
{
    //background View
    UIView *viewOfBackground = [[UIView alloc] initWithFrame:CGRectMake(0, -64, SCREEN_WIDTH, 350)];
    viewOfBackground.userInteractionEnabled = YES;
    viewOfBackground.backgroundColor = [UIColor whiteColor];
    //background image
    UIImageView *imageOfBackground = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"我的背景"]];
    imageOfBackground.frame = CGRectMake(0, 0, SCREEN_WIDTH, 150);
    [viewOfBackground addSubview:imageOfBackground];
    //imageOfPerson
    self.image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, 100, 100)];
    self.image.x_conterX = self.view.x_conterX;
    [self.image sd_setImageWithURL:[NSURL URLWithString:_dictionary[@"avatar"]]];
    self.image.layer.masksToBounds = YES;
    self.image.layer.cornerRadius = 50;
    [viewOfBackground addSubview:self.image];
    self.image.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapImage = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImage:)];
    [_image addGestureRecognizer:tapImage];
    //labelOfName
    UILabel *labelOfName = [[UILabel alloc] initWithFrame:CGRectMake(0, 210, SCREEN_WIDTH, 30)];
    labelOfName.text = _dictionary[@"member_truename"];
    labelOfName.textAlignment = 1;
    labelOfName.font = [UIFont systemFontOfSize:22];
    [viewOfBackground addSubview:labelOfName];
    //labelOfSign
    UILabel *labelOfSign = [[UILabel alloc] initWithFrame:CGRectMake(0, 250, SCREEN_WIDTH, 20)];
    labelOfSign.text = _dictionary[@"member_name"];
    labelOfSign.textColor = [UIColor grayColor];
    labelOfSign.textAlignment = 1;
    [viewOfBackground addSubview:labelOfSign];
    
    //viewOfContract
    UIView *viewOfContract = [[UIView alloc] initWithFrame:CGRectMake(0, 280, (SCREEN_WIDTH - 2) / 3, 70)];
    [viewOfBackground addSubview:viewOfContract];
    UITapGestureRecognizer *tapOfContract = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleContract:)];
    [viewOfContract addGestureRecognizer:tapOfContract];
    
    //labelOfcontract
    UILabel *labelOfContract = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, viewOfContract.bounds.size.width, 20)];
    labelOfContract.text = @"关注的人";
    labelOfContract.textColor = [UIColor grayColor];
    labelOfContract.textAlignment = 1;
    [viewOfContract addSubview:labelOfContract];
    
    //labelOfcontract count
    UILabel *labelOfContractCount = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, viewOfContract.bounds.size.width, 30)];
    labelOfContractCount.text = _dictionary[@"interested_person"];
    labelOfContractCount.textAlignment = 1;
    [viewOfContract addSubview:labelOfContractCount];
    
    //viewOfFans
    UIView *viewOfFans = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 2) / 3 + 1, 280, (SCREEN_WIDTH - 2) / 3, 70)];
    [viewOfBackground addSubview:viewOfFans];
    UITapGestureRecognizer *tapOfFans = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleFans:)];
    [viewOfFans addGestureRecognizer:tapOfFans];
    
    //labelOfFans
    UILabel *labelOfFans = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, viewOfFans.bounds.size.width, 20)];
    labelOfFans.text = @"我的粉丝";
    labelOfFans.textColor = [UIColor grayColor];
    labelOfFans.textAlignment = 1;
    [viewOfFans addSubview:labelOfFans];
    
    //labelOfcontract count
    UILabel *labelOfFansCount = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, viewOfFans.bounds.size.width, 30)];
    labelOfFansCount.text = _dictionary[@"fans"];
    labelOfFansCount.textAlignment = 1;
    [viewOfFans addSubview:labelOfFansCount];
    
    //viewOfWindow
    UIView *viewOfWindow = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 2) / 3 * 2 + 1, 280, (SCREEN_WIDTH - 2) / 3, 70)];
    [viewOfBackground addSubview:viewOfWindow];
    UITapGestureRecognizer *tapOfWindow = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleWindow:)];
    [viewOfWindow addGestureRecognizer:tapOfWindow];
    
    //labelOfWindow
    UILabel *labelOfWindow = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, viewOfWindow.bounds.size.width, 20)];
    labelOfWindow.text = @"关注的橱窗";
    labelOfWindow.textColor = [UIColor grayColor];
    labelOfWindow.textAlignment = 1;
    [viewOfWindow addSubview:labelOfWindow];
    
    //labelOfcontract count
    UILabel *labelOfWindowCount = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, viewOfWindow.bounds.size.width, 30)];
    NSString *str = [_dictionary[@"micro_personal_count"]  stringValue];
    
    labelOfWindowCount.text = str;
    labelOfWindowCount.textAlignment = 1;
    [viewOfWindow addSubview:labelOfWindowCount];
    
    //两条竖线
    UIView *viewOfLine = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 2) / 3 * 2, 280, 1, 60)];
    [viewOfBackground addSubview:viewOfLine];
    viewOfLine.backgroundColor = [UIColor lightGrayColor];
    UIView *viewLine = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 2) / 3, 280, 1, 60)];
    [viewOfBackground addSubview:viewLine];
    viewLine.backgroundColor = [UIColor lightGrayColor];
    _tableView.tableHeaderView = viewOfBackground;

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyTableViewCell"];
    cell.backgroundColor = [UIColor redColor];
    [cell.buttonOfMyGood setImage:[UIImage imageNamed:@"我的订单"] forState:UIControlStateNormal];
        [cell.buttonOfMyGood addTarget:self action:@selector(handleMyGood:) forControlEvents:UIControlEventTouchUpInside];
        
    [cell.buttonOfStore setImage:[UIImage imageNamed:@"关注店铺"] forState:UIControlStateNormal];
    [cell.buttonOfStore addTarget:self action:@selector(handleStore:) forControlEvents:UIControlEventTouchUpInside];
        
    [cell.buttonOfWishes setImage:[UIImage imageNamed:@"心愿单"] forState:UIControlStateNormal];
    [cell.buttonOfWishes addTarget:self action:@selector(handleWishes:) forControlEvents:UIControlEventTouchUpInside];
        
    [cell.buttonOfIlike setImage:[UIImage imageNamed:@"我赞过的"] forState:UIControlStateNormal];
        
    [cell.buttonOfGiftBox setImage:[UIImage imageNamed:@"礼物盒"] forState:UIControlStateNormal];
        [cell.buttonOfGiftBox addTarget:self action:@selector(handleGift:) forControlEvents:UIControlEventTouchUpInside];
        
    [cell.buttonOfMyMoney setImage:[UIImage imageNamed:@"我的资产"] forState:UIControlStateNormal];
        [cell.buttonOfMyMoney addTarget:self action:@selector(handleMoney:) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    } else if(indexPath.section == 1){
        MyTableViewOfMoment *cell = [tableView dequeueReusableCellWithIdentifier:@"MyTableViewOfMoment"];
        cell.arrayOfMoment = _arrayOfMoment;
        NSLog(@"%@", _arrayOfMoment);
        cell.delegate = self;
        return cell;
    } else {
        MyWindowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyWindowTableViewCell"];
        cell.delegate = self;
        cell.arrayOfWindowl = _arrayOfWindow;
        return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 200;
    } else if(indexPath.section == 1){
        NSInteger count = (_arrayOfMoment.count + 1) / 3;
        if ((_arrayOfMoment.count + 1) % 3 == 0) {
            return 120 * count + 20;
        } else {
            return 120 * (count + 1) + 20;
        }
    } else {
        return 240;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    } else {
        return 60;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return nil;
    } else if (section == 1) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 60)];
        view.backgroundColor = [UIColor whiteColor];
        UILabel *labelOfMoment = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80, 60)];
        labelOfMoment.text = @"我的瞬间 ·";
        [view addSubview:labelOfMoment];
        UILabel *labelOdMomentCount = [[UILabel alloc] initWithFrame:CGRectMake(80, 0, 80, 60)];
        NSString *count = [NSString stringWithFormat:@"%ld", _arrayOfMoment.count];
        labelOdMomentCount.text = count;
        [view addSubview:labelOdMomentCount];
        return view;
    } else {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 60)];
        view.backgroundColor = [UIColor whiteColor];
        UILabel *labelOfMoment = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80, 60)];
        labelOfMoment.text = @"我的橱窗 ·";
        [view addSubview:labelOfMoment];
        UILabel *labelOdMomentCount = [[UILabel alloc] initWithFrame:CGRectMake(80, 0, 80, 60)];
        NSString *str = [NSString stringWithFormat:@"%ld", _arrayOfWindow.count];
        labelOdMomentCount.text = str;
        [view addSubview:labelOdMomentCount];

        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(SCREEN_WIDTH - 100, 0, 90, 60);
        [button setTitle:@"查看所有 >" forState:UIControlStateNormal];
        button.tintColor = [UIColor lightGrayColor];
        [button addTarget:self action:@selector(LookMore:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:button];
        return view;
    }
}
- (void)LookMore:(UIButton *)button
{
    LookMoreViewController *look = [[LookMoreViewController alloc] init];
    self.tabBarController.tabBar.hidden = YES;
    look.arrOfModel = _arrayOfWindow;
    [self.navigationController pushViewController:look animated:NO];
}
//设置按钮
- (void)option:(UIBarButtonItem *)barButtonItem
{
    OptionViewController *op = [[OptionViewController alloc]init];
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barItem;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.110 green:0.102 blue:0.196 alpha:1.000];
    self.tabBarController.tabBar.hidden = YES;
    [self.navigationController pushViewController:op animated:NO];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
- (void)handleContract:(UITapGestureRecognizer *)tap
{
    IContractOnViewController *i = [[IContractOnViewController alloc] init];
    self.tabBarController.tabBar.hidden = YES;
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barItem;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.110 green:0.102 blue:0.196 alpha:1.000];
    [self.navigationController pushViewController:i animated:NO];
}
- (void)handleFans:(UITapGestureRecognizer *)tap
{
    MyFansViewController *fans = [[MyFansViewController alloc]init];
    self.tabBarController.tabBar.hidden = YES;
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barItem;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.110 green:0.102 blue:0.196 alpha:1.000];
    [self.navigationController pushViewController:fans animated:NO];
}
- (void)handleWindow:(UITapGestureRecognizer *)tap
{
    NSUserDefaults *userdefault = [NSUserDefaults standardUserDefaults];
    NSString *password = [userdefault objectForKey:@"password"];
    NSString *url = [NSString stringWithFormat:@"http://www.wantease.com/mobile1/index.php?act=member_index&op=more_myself_favorites_showcase&key=%@", password];
    [GXNetWorkingParser GETWithURL:url par:nil success:^(id responseObject) {
        NSArray *arr = responseObject[@"datas"][@"micro_personal_class_list"];
        NSMutableArray *array = [NSMutableArray array];
        for (NSDictionary *dic in arr) {
            ModelOfLookMoreWindow *model = [[ModelOfLookMoreWindow alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [array addObject:model];
        }
        LookMoreViewController *window = [[LookMoreViewController alloc]init];
        window.arrOfModel = array;
        UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
        self.navigationItem.backBarButtonItem = barItem;
        self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.110 green:0.102 blue:0.196 alpha:1.000];
        [self.navigationController pushViewController:window animated:NO];
        
    } filed:^(NSError *error) {
        
    }];
   
}
- (void)momentWithPersonID:(NSString *)person_id
{
    ViewControllerOfHotWindow *hot = [[ViewControllerOfHotWindow alloc]init];
    self.tabBarController.tabBar.hidden = YES;
    hot.person_id = person_id;
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barItem;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.110 green:0.102 blue:0.196 alpha:1.000];
    [self.navigationController pushViewController:hot animated:NO];
}
- (void)myWindowWithID:(NSString *)myID
{
    HotWindowViewController *hot = [[HotWindowViewController alloc] init];
    self.tabBarController.tabBar.hidden = YES;
    hot.favorita_class_id = myID;
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barItem;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.110 green:0.102 blue:0.196 alpha:1.000];
    [self.navigationController pushViewController:hot animated:NO];
}
//she zhi tou xiang 设置头像
- (void)handleImage:(UITapGestureRecognizer *)tap
{
    NSLog(@"点击了头像");
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.editing = YES;
    imagePicker.delegate = self;
    /*
     如果这里allowsEditing设置为false，则下面的UIImage *image = [info valueForKey:UIImagePickerControllerEditedImage];
     应该改为： UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
     也就是改为原图像，而不是编辑后的图像。
     */
    //允许编辑图片
    imagePicker.allowsEditing = YES;
    
    /*
     这里以弹出选择框的形式让用户选择是打开照相机还是图库
     */
    //初始化提示框；
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"设置头像" message:nil preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"照相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        
        [self presentViewController:imagePicker animated:YES completion:nil];
        
    }]];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }]];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        //取消；
    }]];
    //弹出提示框；
    [self presentViewController:alert animated:true completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    //通过info字典获取选择的照片
    UIImage *image = [info valueForKey:UIImagePickerControllerEditedImage];
    //以itemKey为键，将照片存入ImageStore对象中
    [[HeadsPicture sharedHeadsPicture] setImage:image forKey:@"HeadsPicture"];
    //将照片放入UIImageView对象
    self.image.image = image;
    //把一张照片保存到图库中，此时无论是这张照片是照相机拍的还是本身从图库中取出的，都会保存到图库中；
    UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
    //压缩图片,如果图片要上传到服务器或者网络，则需要执行该步骤（压缩），第二个参数是压缩比例，转化为NSData类型；
//    NSData *fileData = UIImageJPEGRepresentation(image, 1.0);
    //关闭以模态形式显示的UIImagePickerController
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)handleStore:(UIButton *)button
{
    ContractStoreViewController *store = [[ContractStoreViewController alloc]init];
    self.tabBarController.tabBar.hidden = YES;
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barItem;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.110 green:0.102 blue:0.196 alpha:1.000];
    [self.navigationController pushViewController:store animated:NO];
}
- (void)handleWishes:(UIButton *)button
{
    MyWishesViewController *mywish = [[MyWishesViewController alloc]init];
    self.tabBarController.tabBar.hidden = YES;
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barItem;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.110 green:0.102 blue:0.196 alpha:1.000];
    [self.navigationController pushViewController:mywish animated:NO];
}
- (void)handleMyGood:(UIButton *)button
{
    MyPreListViewController *vc = [[MyPreListViewController alloc]init];
    self.tabBarController.tabBar.hidden = YES;
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barItem;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.110 green:0.102 blue:0.196 alpha:1.000];
    [self.navigationController pushViewController:vc animated:NO];
}
- (void)handleGift:(UIButton *)button
{
    GiftViewController *gift = [[GiftViewController alloc]init];
    self.tabBarController.tabBar.hidden = YES;
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barItem;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.110 green:0.102 blue:0.196 alpha:1.000];
    [self.navigationController pushViewController:gift animated:NO];
}
- (void)handleMoney:(UIButton *)button
{
    MyMoneyViewController *vc = [[MyMoneyViewController alloc]init];
    self.tabBarController.tabBar.hidden = YES;
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barItem;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.110 green:0.102 blue:0.196 alpha:1.000];
    [self.navigationController pushViewController:vc animated:NO];
}
@end
